var t = require("../../../@babel/runtime/helpers/createForOfIteratorHelper"), e = getApp();

Page({
    data: {
        value: 3,
        reComment: "",
        comment: "",
        good: "",
        item: "",
        uploadUrl: "upload.uploadPic",
        fileList3: [],
        fileList4: [],
        upNumMaxOther: 0
    },
    onLoad: function(t) {
        JSON.parse(t.item) && (this.setData({
            good: JSON.parse(t.item)
        }), this.setData({
            goods_id: this.data.good.goods_id,
            order_id: t.order_id,
            order_goods_id: this.data.good.id
        }), this.getNetData());
    },
    getNetData: function() {
        var t = this, a = e.getNetAddresss("goods.comment.append-comment-page");
        e._postNetWork({
            url: a,
            data: {
                goods_id: this.data.goods_id,
                order_id: this.data.order_id,
                order_goods_id: this.data.order_goods_id
            },
            success: function(e) {
                var a = e.data;
                1 != a.result ? wx.showToast({
                    title: a.msg,
                    icon: "none"
                }) : t.setData({
                    item: a.data.comment,
                    value: a.data.comment.level,
                    comment: a.data.comment.content
                });
            }
        });
    },
    commentChange: function(t) {
        var e = t.detail;
        this.setData({
            reComment: e
        });
    },
    toReComment: function() {
        var t = this;
        0 == this.data.reComment.length ? wx.showModal({
            title: "提示",
            content: "您还没有输入相关的评论内容",
            success: function(e) {
                e.confirm && t._submitData();
            }
        }) : this._submitData();
    },
    _submitData: function() {
        var t = e.getNetAddresss("goods.comment.append-comment"), a = {
            id: this.data.item.id,
            order_goods_id: this.data.order_goods_id,
            content: this.data.reComment
        };
        if (0 != this.data.fileList3.length) {
            var i = this.data.fileList3.map(function(t) {
                return t.url;
            });
            a.images = JSON.stringify(i);
        }
        e._postNetWork({
            url: t,
            showToastIn: !1,
            data: a,
            success: function(t) {
                var e = t.data;
                1 == e.result ? wx.showToast({
                    title: e.msg,
                    icon: "none",
                    duration: 1500,
                    success: function() {
                        setTimeout(function() {
                            wx.navigateBack({
                                delta: 1
                            });
                        }, 1500);
                    }
                }) : wx.showToast({
                    icon: "none",
                    title: e.msg,
                    duration: 1500
                });
            },
            fail: function(t) {}
        });
    },
    onRead_2: function() {
        if (5 == this.data.upNumMaxOther || this.data.upNumMaxOther >= 5) return wx.showToast({
            icon: "none",
            title: "图片数量已达到上限",
            duration: 1500
        }), !1;
        var a = this, i = e.getNetAddresss(this.data.uploadUrl);
        wx.chooseImage({
            count: 5 - this.data.upNumMaxOther,
            sizeType: [ "original", "compressed" ],
            sourceType: [ "album", "camera" ],
            success: function(e) {
                var s, o = e.tempFilePaths, n = t(o);
                try {
                    for (n.s(); !(s = n.n()).done; ) {
                        var d = s.value;
                        wx.compressImage({
                            src: d,
                            quality: 60,
                            success: function(t) {
                                var e = t.tempFilePath;
                                wx.uploadFile({
                                    url: i,
                                    filePath: e,
                                    name: "file",
                                    formData: {
                                        attach: "upload"
                                    },
                                    success: function(t) {
                                        var i = JSON.parse(t.data);
                                        if (1 == i.result) {
                                            var s = a.data.fileList3, o = a.data.fileList4;
                                            s.push({
                                                url: i.data.img
                                            }), o.push({
                                                url: e
                                            }), a.setData({
                                                upNumMaxOther: a.data.upNumMaxOther + 1,
                                                fileList3: s,
                                                fileList4: o
                                            });
                                        } else wx.showToast({
                                            icon: "none",
                                            title: i.msg,
                                            duration: 1500
                                        });
                                    }
                                });
                            },
                            fail: function(t) {},
                            complete: function(t) {}
                        });
                    }
                } catch (t) {
                    n.e(t);
                } finally {
                    n.f();
                }
            }
        });
    },
    removeImg_1: function(t) {
        var e = t.currentTarget.dataset.index, a = this.data.fileList3, i = this.data.fileList4;
        a.splice(e, 1), i.splice(e, 1), this.setData({
            fileList3: a,
            fileList4: i
        }), this.setData({
            upNumMaxOther: this.data.fileList3.length
        });
    }
});